local huaiju = fk.CreateSkill{
  name = "wk_heg__huaiju"
}

Fk:loadTranslationTable{
  ["wk_heg__huaiju"] = "怀橘",
  [":wk_heg__huaiju"] = "其他势力角色的指定你为目标的非伤害牌结算后，你可令一名除使用者外的角色获得此牌，然后此牌使用者可弃置你一张牌。",

  ["#wk_heg__huaiju_choose"] = "怀橘：你可以将此牌交给一名除使用者外的角色",
  ["#wk_heg__huaiju_discard_choose"] = "弃置 %dest 的一张牌",

  ["$wk_heg__huaiju1"] = "情深舐犊，怀拙藏橘。",
  ["$wk_heg__huaiju2"] = "袖中怀绿橘，遗母报乳哺。",
}

local H = require "packages/ol_hegemony/util"

huaiju:addEffect(fk.CardUseFinished,{
  anim_type = "special",
  can_trigger = function (self, event, target, player, data)
    if not (player:hasSkill(huaiju.name) and not H.compareKingdomWith(player, target) and data.tos and
    table.find(data.tos, function(id) return id == player end)) then return false end
    return not data.card.is_damage_card and table.every(Card:getIdList(data.card), function (id) return player.room:getCardArea(id) == Card.Processing end)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function(p) return p ~= target end)
    local tos = room:askToChoosePlayers(player,{
        targets = targets,
        min_num = 1,
        max_num = 1,
        prompt = "#wk_heg__huaiju_choose",
        skill_name = huaiju.name,
        cancelable = true,
    })
    if #tos > 0 then
      event:setCostData(self,{ tos = tos })
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local card_ids = Card:getIdList(data.card)
    if #card_ids == 0 then return false end
    room:moveCardTo(card_ids, Player.Hand, event:getCostData(self).tos[1], fk.ReasonPrey, huaiju.name, nil, true, player.id)
    local choices = {"Cancel"}
    if player:isAlive() and #player:getCardIds("he") > 0 then
      table.insert(choices, 1, "#wk_heg__huaiju_discard_choose::" .. player.id)
    end
    local choice = room:askToChoice(target, {choices = choices, skill_name = huaiju.name})
    if choice ~= "Cancel" then
      local cid = room:askToChooseCard(target,{
        target = player,
        flag = "he",
        skill_name = huaiju.name
      })
      room:throwCard({cid}, huaiju.name, player, target)
    end
  end,
})

return huaiju